package com.example.demo.topic;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class TopicQueueConfig {

    public static final String queueName0 = "topicMessage0";
    public static final String queueName1 = "topicMessage1";

    public static final String exchange = "topicExchange";


    public static final String routingKey0 = "topic.message0";
    public static final String routingKey1 = "topic.message1";
    public static final String routingKey2 = "topic.#";//#(井号)可以匹配零个或多个单词,*(星号)可以匹配一个单词

    @Bean
    public Queue topicMessage0() {
        return new Queue(queueName0);
    }

    @Bean
    public Queue topicMessage1() {
        return new Queue(queueName1);
    }

    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange(exchange);
    }

    @Bean
    Binding bindingTopicExchange0(Queue topicMessage0, TopicExchange topicExchange) {

        return BindingBuilder.bind(topicMessage0).to(topicExchange).with(routingKey0);
    }


    @Bean
    Binding bindingTopicExchange1(Queue topicMessage1, TopicExchange topicExchange) {

        return BindingBuilder.bind(topicMessage1).to(topicExchange).with(routingKey1);
    }

    @Bean
    Binding bindingTopicExchange2(Queue topicMessage1, TopicExchange topicExchange) {

        return BindingBuilder.bind(topicMessage1).to(topicExchange).with(routingKey2);
    }


}
